package com.bt7274.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bt7274.pojo.ReportRecord;
import com.bt7274.service.ReportService;
import com.bt7274.grace.result.GraceJSONResult;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/report")
public class ReportController {

    @Autowired
    private ReportService reportService;

    // 用户提交举报
    @PostMapping
    public GraceJSONResult submitReport(@RequestBody ReportRecord reportRecord) {
        try {
            reportService.submitReport(reportRecord);
            return GraceJSONResult.ok("举报成功");
        } catch (Exception e) {
            return GraceJSONResult.errorMsg("举报失败：" + e.getMessage());
        }
    }

    // 管理员查询举报列表
    @GetMapping("/list")
    public GraceJSONResult getReports(
            @RequestParam(defaultValue = "all") String filter,
            @RequestParam(required = false) String reportedType,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int pageSize) {
        Page<ReportRecord> list = reportService.getReports(filter, reportedType, page, pageSize);

        return GraceJSONResult.ok(list);
    }

    // 查看某人的举报记录
    @GetMapping("/reporter")
    public GraceJSONResult getMyReports(@RequestParam String reporterId,
                                        @RequestParam(defaultValue = "1") int page,
                                        @RequestParam(defaultValue = "10") int pageSize) {
        Page<ReportRecord> list = reportService.getReportsByReporter(reporterId, page, pageSize);
        return GraceJSONResult.ok(list);
    }

    // 管理员处理举报
    @PostMapping("/process")
    public GraceJSONResult processReport(@RequestParam Long reportId,
                                         @RequestParam Integer status,
                                         @RequestParam String processResult) {
        try {
            reportService.processReport(reportId, status, processResult);
            return GraceJSONResult.ok("处理成功");
        } catch (Exception e) {
            return GraceJSONResult.errorMsg("处理失败：" + e.getMessage());
        }
    }


}
